<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #container{
            width:5rem;
            background-color: green;
            height:5rem;
        }
    </style>
</head>
<body>
    <div id="container">

    </div>
    <script>
        let docElement = document.documentElement;
        function  setREMUnit(){
            docElement.style.fontSize= docElement.clientWidth/10+'px';
        }
        setREMUnit();
        //当屏幕宽度发生变化时，重新计算rem的值
        window.addEventListener('resize',setREMUnit);
    </script>
</body>
</html>